package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记推荐
 */
@Setter
@Getter
public class TravelCommend extends BaseDomain{
    public static final int TYPE_WEEK = 0;//每周推荐
    public static final int TYPE_MONTH = 1;//每月推荐
    public static final int TYPE_STRATEGY = 2;//攻略推荐

    //关联游记
    private Travel travel;
    //标题
    private String title;
    //副标题
    private String subTitle;
    //封面
    private String coverUrl;
    //推荐时间安排
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;
    //推荐类型
    private Integer type=TYPE_WEEK;


    public String getTypeName(){
        String temp = "每周推荐";
        if(type==TYPE_MONTH){
            temp = "每月推荐";
        }else if(type==TYPE_STRATEGY){
            temp = "攻略推荐";
        }
        return temp;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        //将需要的数据添加到map集合中
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        if (schedule != null) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            map.put("schedule", simpleDateFormat.format(schedule));
        }
        map.put("coverUrl",coverUrl);
        map.put("type",type);
        if (travel!=null) {
            map.put("travelId", travel.id);
        }
        //将map集合转换成json格式的字符串,再返回
        return JSON.toJSONString(map);
    }


}